package com.syb.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.syb.dao.LoginDao;
import com.syb.entity.function.SysResource;
import com.syb.entity.function.SysRole;
import com.syb.entity.user.SysUser;
import com.syb.service.LoginService;

@Service
public class LoginServiceImpl implements LoginService {
	
	@Autowired
	private LoginDao loginDao;
	

	/**
	 * ��½��ѯ
	 */
	public Map<String,Object> findSysUser(String name,String password) throws Exception {
		Map<String,Object> map = new HashMap<String,Object>();
		List<SysUser> sysUser = new ArrayList<SysUser>();
		List<SysResource> sysResource = new ArrayList<SysResource>();
		List<SysRole> sysRole = new ArrayList<SysRole>();
		try{
			sysUser = loginDao.querySysUser(name, password);
		}catch(Exception e){
			throw new Exception(e.getMessage());
		}
		if(sysUser!=null){
			try{
				sysResource = loginDao.querySysResource(sysUser.get(0).getId());
			}catch(Exception e){
				throw new Exception(e.getMessage());
			}
			try{
				sysRole = loginDao.querySysRole(sysUser.get(0).getId());
			}catch(Exception e){
				throw new Exception(e.getMessage());
			}
		}
		map.put("sysUser", sysUser.get(0));
		map.put("sysRole", sysRole);
		map.put("sysResource", sysResource);
		return map;
	}


	
}
